package com.controller.${packageName};

import com.entity.common.ApiResult;
import com.service.${packageName}.${moduleName ? cap_first}Service;
import com.entity.${packageName}.${moduleName ? cap_first};
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by System on ${createDate}.
 */
@RestController
@RequestMapping("${moduleName}")
public class ${moduleName ? cap_first}Controller {

    @Autowired
    private ${moduleName ? cap_first}Service ${moduleName}Service;

    @RequestMapping("/getPageList")
    public Map<String,Object> getPageList(@RequestParam(value = "pager.pageNo",defaultValue ="1" )  Integer pageNum,
                @RequestParam(value = "pager.pageSize",defaultValue ="10" ) Integer pageSize,${moduleName ? cap_first} ${moduleName}){
        Map<String, Object> map=new HashMap<>();
        PageHelper.startPage(pageNum,pageSize);
        PageInfo<${moduleName ? cap_first}> pageInfo = new PageInfo<>(${moduleName}Service.getPageList(${moduleName}));
        map.put("rows",pageInfo.getList());
        map.put("pager.totalRows", pageInfo.getTotal());
        map.put("pager.pageNo",pageNum);
        return  map;
    }

    @RequestMapping("/add${moduleName ? cap_first}")
    public ApiResult add${moduleName ? cap_first}(${moduleName ? cap_first} ${moduleName}){
        return ${moduleName}Service.add${moduleName ? cap_first}(${moduleName});
    }

    @RequestMapping("/delete${moduleName ? cap_first}")
    public ApiResult delete${moduleName ? cap_first}(Long id){
        return ${moduleName}Service.delete${moduleName ? cap_first}(id);
    }

    @RequestMapping("/get${moduleName ? cap_first}ById")
    public ApiResult get${moduleName ? cap_first}ById(Long id){
        return ${moduleName}Service.get${moduleName ? cap_first}ById(id);
    }

    @RequestMapping("/edit${moduleName ? cap_first}")
    public ApiResult edit${moduleName ? cap_first}(${moduleName ? cap_first} ${moduleName}){
        return ${moduleName}Service.edit${moduleName ? cap_first}(${moduleName});
    }

}
